<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: view.html.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class JhtraqViewProjects extends JView {
    function display($tpl = null) {

		$task = JRequest::getCmd('task', 'index');
		$tpl = $this->$task();
		
        parent::display($tpl);
    }
	
	function index()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->projects =  $model->getProjects();
		$this->search = JRequest::getVar('search');
		$this->pagination = $model->getPagination();
		
	}

        function amibros_tickets()
        {
             $results = array();
             $results[0] = JText::_('COM_JHTRAQ_NONE');
            if(file_exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ambrasubs' . DS . 'ambrasubs.php'))
            {

                $db =&JFactory::getDBO();
                $db->setQuery("Select id, title from #__ambrasubs_types order by title asc ");
                $rows = $db->loadAssocList();

                foreach($rows as $row){
                    $results[$row['id']] = $row['title'];
                }
            }

            return $results;
        }
	
	function add()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->project = $model->getProject(0);
		$this->users = $model->getUserList();
		$this->groups = $model->getUserGroups();
		return 'form';
	}
	
	function edit()
	{
	    $cid = JRequest::getVar( 'cid', array(), '', 'array' );
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->project = $model->getProject($cid[0]);
		$this->users = $model->getUserList();
		$this->groups = $model->getUserGroups();
		return 'form';
	}
	
	function save()
	{
		$detail = $_POST;
		$model =& JhtraqHelper::getModel('jhtraq');
		$model->saveProject($detail);
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=projects", "Projects Updated");
	}
	
	
	function remove()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$model->removeProject($_POST['cid']);
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=projects", "Projects Deleted");
	}
	/**
	 * cancel editing a record
	 * @return void
	*/
	function cancel()
	{
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=projects", JText::_('COM_JHTRAQ_OPERATION_CANCELLED'));
	}
	
}
?>